package main

import "github.com/Unknwon/goconfig"

type Header struct {
	Key   string
	Value string
}

func (h Header) init(section, path string) []Header {
	config, _ := goconfig.LoadConfigFile(path)
	keyList := config.GetKeyList(section)
	if keyList == nil {
		return nil
	}
	headers := make([]Header, len(keyList))
	for k, v := range keyList {
		value, _ := config.GetValue(section, v)
		headers[k] = Header{Key: v, Value: value}
	}
	return headers
}

func (h Header) initHeader(path string) []Header {
	return h.init("Header", path)
}

func ToMap(path string) map[string]string {
	headers := Header{}.initHeader(path)
	result := map[string]string{}
	if headers == nil {
		return result
	}
	for _, v := range headers {
		result[v.Key] = v.Value
	}
	return result
}
